/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',"business/index/services/httpServices","i18n","jquery","domReady","business/services/services",
    "jqueryMedia","business/library/directives/engDetailDirective","business/home/directives/translate",
    "business/index/services/directives","business/index/services/direc2","business/index/services/engSpecial","business/services/filter"],function(require,app,httpService,i18n){
    app.controller('indexCtrl',function($scope,$state,$stateParams,auth,$q){
        $scope.isDetailPage = false;
        $scope.isMainpage = true;
		$scope.activeTag = 1;
        $scope.goIndexCtrl = function(){
            $state.transitionTo('indexCtrl',{},{reload: true, inherit: false, notify: true});
        }
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?a799a6d3499969014708c65f343ad035";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
        //获取专题列表
        subjectList();
        function subjectList(){
            var req={
                type:"get",
                uri:"getList",
                removeCookie:true
            };
            httpService.subjectHttpService(req).success(function(data){
                $scope.specialDataList=data.data.list;
                $scope.$apply(function(){
                    $('.banner-container').css('width',(290+13)*($scope.specialDataList.length)-13);
                    $scope.len=Math.ceil($scope.specialDataList.length/4);
                });
            }).error(function(msg){
                console.log(msg);
            })
        }
        //工程专题轮播
        function Play(){
            var i= 0;
            this.move=function(dir,len,width){
                if(dir=='next'){i++;}
                if(dir=='pre'){i--;}
                if(i>=len){i=len-1;}//$('.banner-container').css('marginLeft',0)
                if(i<=0){i=0;}//$('.banner-container').css('marginLeft',-width*len)
                $('.banner-container').stop().animate({marginLeft:-width*i},600);
            }
        }
        var bannerPaly=new Play();
        $scope.dirction=function(dir){
            bannerPaly.move(dir,$scope.len,290+13);
        };

        //首页广告列表
        getAdverList();
        function getAdverList(){
            var req={
                type:"get",
                uri:"getList",
                data:{
                    bigCount:100,
                    smallCount:100
                },
                removeCookie:true
            };
            httpService.adverHttpService(req).success(function(data){
                $scope.bigAdverList=data.data.bigBanner;
                $scope.smallAdverList=data.data.smallBanner;
            }).error(function(msg){
                console.log(msg);
            })
        }

        //首页导航
        $scope.i18n = i18n;
        var param = $stateParams;
        $scope.stateGoTo = function (state,num){
            if(state == "login"){
                var param = $state.current.name;
                sessionStorage.currentUrl = param ;
                if( typeof  num == "number"){
                    sessionStorage.loginType = null;
                    if(num == 0){
                        sessionStorage.loginType = 0;
                    }else if(num ==1){
                        sessionStorage.loginType = 1;
                    }
                }
                $state.go(state);
            }else{
                $state.go(state);
            }
        };
        //$state.go("eng.indexCtrl");
        //默认路由视图
        //  $scope.routerChange($scope.state.engMain);

        $scope.showNavBox = false;
        $scope.navClass = "f-nav-out";
        //鼠标进入 改变导航区样式
        $scope.changeNav = function(curClass){
            if(curClass=$scope.navClass){
                $scope.navClass = "f-nav-enter";
            }
            $scope.showNavBox = true;
        };
        //鼠标移除 改变导航区样式
        $scope.mouseleave = function(mouseover){
            $scope.showNavBox = false;
            $scope.navClass = "f-nav-out"
        };
        //后台查询数据或缓存中查询数据。
        $scope.data = {
            "username":"Da Anna"
        };
        $scope.placeholder = "请输入您要输入的内容";
        $scope.mainData = {
            logoSrc:"them/images/gcj_big_logo.png"
        }


        // 点击资料 显示下拉框
        $scope.isShowData = false;
        $scope.isInList = false;
        $scope.clickData = function(){
            if($scope.isShowData == false){
                $scope.isShowData = true;
            }
        };
        $scope.leaveSearchList =function(){
            if($scope.isShowData == true){
                $scope.isShowData = false;
            }
            $scope.isInList = true;
        };

        $scope.showBanner = false;
        $scope.onchange = {
            careEnter:function(){
                $scope.showBanner = true;
            },
            careLeave :function(){
                $scope.showBanner = false;
            }
        }


		//回到顶部
		$('.goBackTop a').eq(1).click(function(){
			$('body,html').animate({scrollTop:0},500);
		})

        $scope.tab=1;//头部新闻点击切换，默认显示第一个
        $scope.twoTab = 2;//第二栏目切换默认显示第一个
        $scope.ftab=1;//尾部友情链接默认第一个
        $scope.thtab = 1;
		$scope.goto1 = function(ctrl){
			$state.go(ctrl,{},{reload:true})
		}
        $scope.gotoAsk = function(){
            auth.isLogin().then(function(){

            })
        }
		//获取工程资料库一级接口
		function getTopCategory(){
			var req = {
                type:"GET",
                uri:"getTopCategory",
                data:{

                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.topCategory = response.data;
                })
            });
		}
		getTopCategory();
		
		//获取国内工程资料库
		function getHomeCategory(){
			var req = {
                type:"GET",
                uri:"getSecondaryCategory",
                data:{
                    tcId:1
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.homeCategory = response.data;
                })
            });
		}
		getHomeCategory();
		//获取国际工程资料库二级接口
		function getSecondaryCategory(){
			var req = {
                type:"GET",
                uri:"getSecondaryCategory",
                data:{
                    tcId:2
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.secondCategory = response.data;
                    getDetailCategory($scope.secondCategory[0].scId);
                })
            });
		}
		getSecondaryCategory();
		//获取工程资料库三级接口
		
		//获取国际工程资料库三级
		$scope.getDetail = function(i,scId){
			$scope.thtab = i;
			getDetailCategory(scId);
		}
		function getDetailCategory(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                    scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                	$scope.detailCategory = response.data;
                	$scope.detailCountry = [];
					$scope.detailMajor = [];
					$scope.detailKind = [];
                    $scope.detailNew = [];
                	angular.forEach($scope.detailCategory,function(data){
                		if(data.dcType == 1 || data.dcType == 4 || data.dcType == 7){
							$scope.detailMajor.push(data);
                		}else if(data.dcType == 2 || data.dcType == 5 || data.dcType == 8){
                			$scope.detailCountry.push(data)
                		}else if(data.dcType == 3 || data.dcType == 6 || data.dcType == 9){
                			$scope.detailKind.push(data)
                		}else if(data.dcType == 10){
                            $scope.detailNew.push(data);
                        }
                	})
                })
                
            }); 
		}

		//获取国内工程资料库三级
		$scope.getHomeDetail = function(scId){
			
		}
		//获取建筑、城市规划和园林
        getBuildingDetail(1).then(function(data){
            $scope.buildDetail=data;
        });
        getBuildingDetail(2).then(function(data){
            $scope.parkDetail=data;
        });
		$scope.getHomeTwoDetail = function(scId1,scId2,scId3,scId4){
            if(arguments.length==3){
                getBuildingDetail(scId3).then(function(data){
                    $scope.threeDetail=data;
                });
                /*getBuildingDetail(scId4).then(function(data){
                    $scope.fourDetail=data;
                });*/
            }
            getBuildingDetail(scId1).then(function(data){
                $scope.buildDetail=data;
            });
            getBuildingDetail(scId2).then(function(data){
                $scope.parkDetail=data;
            });
		};
		//获取建筑
		function getBuildingDetail(scId){
            var deferred = $q.defer();
            var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                    scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    deferred.resolve(response.data);
                })
            }).error(function(){
                deferred.reject();
            });
            return deferred.promise;
        }
		//获取国内其他三级分类
		$scope.getOtherHomeDetail = function(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                    scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                	$scope.otherHomeDetail = response.data;
                })
            }); 
		}
		
		//导航搜索进入工程资料库
		$scope.searchMain = function(tc,sc,dc){
			var obj = {
				tcId:tc,
				scId:sc,
				dcId:dc
			}
			var str = JSON.stringify(obj);
			sessionStorage.engParams = str;
			$state.go('eng.main');
		}
		//进入职业考证体系
        $scope.practice = function(tc,sc,dc){
            var obj = {
                tcId:tc,
                scId:sc
            }
            var str = JSON.stringify(obj);
            sessionStorage.engParams = str;
            $state.go('eng.practiceMain');
        }
		
		
		
		
		//获取工程资料精选
		function getFileBest(){
			var req = {
                type:"GET",
                uri:"getFileBest",
                data:{
                }
            };
            httpService.fileHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.fileBest = response.data;
                })
            });
		}
		getFileBest();
		
		//获取论文精选
		function getThesisBest(){
			var req = {
                type:"GET",
                uri:"getThesisBest",
                data:{
                	count:5
                }
            };
            httpService.libraryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                	
                    $scope.libraryBest = response.data;
                })
            });
		}
		getThesisBest();
		
		//获取视频精选
		function getHotCourse(){
			var req = {
                type:"GET",
                uri:"getHotCourse",
                data:{
                	pageNo:1,
                	pageSize:5,
                	all:false
                }
            };
            httpService.courseHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.hotCourse = response.data.list;
                })
            });
		}
		//getHotCourse();
		//获取院校专区
		function getNewsBest(){
			var req = {
                type:"GET",
                uri:"getNewsBest",
                data:{
                	pageNo:1,
                	count:4,
                	all:false
                }
            };
            httpService.newsHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.newsBest = response.data;
                    $scope.newsBestUl = $scope.newsBest.slice(1);
                })
            });
		}
		getNewsBest();
		
		//获取职业规划体系
		function getPlannhier(){
			var req = {
                type:"GET",
                uri:"getList",
                data:{
                	pageNo:1,
                	pageSize:10,
                	all:false
                }
            };
            httpService.plannhierHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.plannhier = response.data.list;
                })
            });
		}
		//getPlannhier();

        //国际工程国际商务
        $scope.changeTab = 1;
        $scope.ecoTab = function(item){
            $scope.changeTab = item;
        }

		//获取百问百答
		function getPostbarOfIndex(){
			var req = {
                type:"GET",
                uri:"getPostbarOfIndex",
                data:{
                	count:5
                }
            };
            httpService.postbarHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.postbar = response.data;
                })
            });
		}
		getPostbarOfIndex();
		
		//获取考证公告
		function getNewsNotice(){
			var req = {
                type:"GET",
                uri:"getNewsNotice",
                data:{
                	count:8
                }
            };
            httpService.newsHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.newsNotice = response.data;
                })
            });
		}
		getNewsNotice();
		
		//获取工程技能体系
		//获取软件技能
		function getSoftwareSkill(){
			var req = {
                type:"GET",
                uri:"getList",
                data:{
                	tcId:5,
                    pageNo:1,
                	pageSize:5,
                    count:6,
                    visitCount:true,
                    publishTime:true
                }
            };
            httpService.skillHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.softwareSkill = response.data.list;
                })
            });
		}
		//getSoftwareSkill();
		//获取工程设备技能
		function getEngSkill(){
			var req = {
                type:"GET",
                uri:"getList",
                data:{
                	tcId:6,
                    pageNo:1,
                    pageSize:5,
                    count:6,
                    visitCount:true,
                    publishTime:true
                }
            };
            httpService.skillHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.engSkill = response.data.list;
                })
            });
		}
		//getEngSkill();
		//获取实验仪器技能
		function getTestSkill(){
			var req = {
                type:"GET",
                uri:"getList",
                data:{
                	tcId:7,
                    pageNo:1,
                    pageSize:5,
                    count:6,
                    visitCount:true,
                    publishTime:true
                }
            };
            httpService.skillHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.testSkill = response.data.list;
                })
            });
		}
		//getTestSkill();

		//获取建筑类别体系
		function getBuildCategory(){
			var req = {
                type:"GET",
                uri:"getBuildCategory",
                data:{
                	
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.buildCategory = response.data;
                    getDetailCategory1(response.data[0].scId);
                    getDetailCategory2(response.data[1].scId);
                    getDetailCategory3(response.data[2].scId);
                    getDetailCategory4(response.data[3].scId);
                })
            });
		}
		//getBuildCategory();
		//获取公共建筑三级分类
		function getDetailCategory1(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                	scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.detailBuild1 = response.data;
                })
            });
		}
		
		//获取居住建筑三级分类
		function getDetailCategory2(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                	scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.detailBuild2 = response.data;
                })
            });
		}
		//获取工业建筑三级分类
		function getDetailCategory3(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                	scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.detailBuild3 = response.data;
                })
            });
		}
		
		//获取农业建筑
		function getDetailCategory4(scId){
			var req = {
                type:"GET",
                uri:"getDetailCategory",
                data:{
                	scId:scId
                }
            };
            httpService.categoryHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.detailBuild4 = response.data;
                })
            });
		}
		//获取职业考证体系
		function getFileSystem(){
			var req = {
                type:"GET",
                uri:"getFileSystem",
                data:{
                	count:5
                }
            };
            httpService.fileHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.fileSystem = response.data.fileSystem;
                })
            });
		}
		getFileSystem();
		function getFile(){
			var req = {
                type:"GET",
                uri:"getFile",
                data:{
                	count:6
                }
            };
            httpService.fileHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.file = response.data.file;
                })
            });
		}
		getFile();
		//获取行业资讯
		$scope.getTrade = function(i,tcId){
			$scope.tab = i;
			getNewsTrade(tcId)
		}
		
		function getNewsTrade(scId){
			var req = {
                type:"GET",
                uri:"getNewsTrade",
                data:{
                	count:8,
                	scId:scId,
                }
            };
            httpService.newsHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    $scope.newsTrade = response.data;
                    $scope.newsTradeUl = $scope.newsTrade.slice(1);
                })
            });
		}
		getNewsTrade(49);
		//进入建筑类别体系
		$scope.goBuild = function(sc,dc){
            var obj = {
                scId:sc
            }
            if(dc){
                obj.dcId = dc;
            }
            var str = JSON.stringify(obj);
            sessionStorage.engParams = str;
            $state.go('eng.buildClass');
        }
		//进入工程技能体系
        $scope.goSkill = function(tc){
            sessionStorage.worlListId = tc;
            $state.go('eng.workListCtrl');
        }
		
		//跳转各个详情页
		$scope.goto = function(item,Id,ctrl){
			if(item == 'fileId'){
				$state.go(ctrl,{'fileId':Id},{reload:true})
			}else if(item == 'newsId'){
				$state.go(ctrl,{'newsId':Id})
			}else if(item == 'thesisId'){
				$state.go(ctrl,{'thesisId':Id})
			}else if(item == 'postbarId'){
				$state.go(ctrl,{'postbarId':Id})
			}else if(item == 'courseId'){
				$state.transitionTo(ctrl,{'courseId':Id},{reload:true,inherit:false,notify:true})
			}else if(item == 'hierId'){
				$state.go(ctrl,{'hierId':Id})
			}else if(item == 'skillId'){
                $state.go(ctrl,{'skillId':Id})
            }
			
		}
		
		$scope.linkHunti=function(id){
			$state.go("special",{subjectId:id})
		}
        $scope.goCompany = function(){
            $state.go('outIndexCtrl.companyResourceCtrl',{companyId:'f35f7072060d44b5a976f240925921c2'});
        }

        function getInternationalFileBest(){
            var req = {
                type:"GET",
                uri:"getInternationalFileBest",
                data:{
                    count:5
                }
            };
            httpService.fileHttpService(req).success(function(response){
                if(!response.data) return;
                $scope.$apply(function(){
                    console.log(response.data)
                    $scope.fileStandard = response.data.fileStandard;
                    $scope.fileProject = response.data.fileProject;
                    $scope.fileBusiness = response.data.fileBusiness;
                })
            });
        }
        getInternationalFileBest();


        $scope.friendSrc = [{
            src:'them/imag/logo1.png'
        },{
            src:'them/imag/2.png'
        },{
            src:'them/imag/3.png'
        },{
            src:'them/imag/4.png'
        },{
            src:'them/imag/5.png'
        },{
            src:'them/imag/6.png'
        },{
            src:'them/imag/7.png'
        },{
            src:'them/imag/8.png'
        },{
            src:'them/imag/9.png'
        },{
            src:'them/imag/15.png'
        },{
            src:'them/imag/11.png'
        },{
            src:'them/imag/12.png'
        },{
            src:'them/imag/13.png'
        },{
            src:'them/imag/14.png'
        }]

    })
})


